    /*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package lk.asha.desktop.beans;

import java.awt.Color;
import java.io.File;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.JOptionPane;
import javax.swing.text.JTextComponent;
import lk.asha.desktop.style.Style;

/**
 *
 * @author user
 */
public class CheckFeild {
   public  boolean b=true;
    public boolean checkInteger(String string){
        try {
            int a=Integer.parseInt(string);

            return true;
        } catch (Exception e) {
        }
        JOptionPane.showMessageDialog (null, "please enter a number.", "Title", JOptionPane.WARNING_MESSAGE);
        b=false;
    return false;
    }

        public boolean checkInteger(JTextComponent jTextComponent){
        try {
            int a=Integer.parseInt(jTextComponent.getText());
            jTextComponent.setBackground(Color.white);
            return true;
        } catch (Exception e) {
        }
         jTextComponent.setBackground(new Style().getTextFieldErrorBlackground());
        JOptionPane.showMessageDialog (null, "please enter a number.", "Title", JOptionPane.WARNING_MESSAGE);
        b=false;
    return false;
    }
public boolean checkDoule(String string){
        try {
           Double.parseDouble(string);
            return true;
        } catch (Exception e) {
        }
        JOptionPane.showMessageDialog (null, "please enter the price.", "Title", JOptionPane.WARNING_MESSAGE);
        b=false;
    return false;
    }
public boolean checkDoule(JTextComponent jTextComponent){
        try {
           Double.parseDouble(jTextComponent.getText());
           jTextComponent.setBackground(Color.white);
            return true;
        } catch (Exception e) {
        }
        jTextComponent.setBackground(new Style().getTextFieldErrorBlackground());
        JOptionPane.showMessageDialog (null, "please enter the price.", "Title", JOptionPane.WARNING_MESSAGE);
        b=false;
    return false;
    }
public boolean checkEmpty(String string){

    if (string.length()!=0) {
    return true;

    }
     JOptionPane.showMessageDialog (null, "please enter the value.", "Title", JOptionPane.WARNING_MESSAGE);
return false;
}
public boolean checkEmpty(JTextComponent jTextComponent){

    if (jTextComponent.getText().length()!=0) {
        jTextComponent.setBackground(Color.white);
    return true;

    }
    jTextComponent.setBackground(new Style().getTextFieldErrorBlackground());
     JOptionPane.showMessageDialog (null, "please enter the  value.", "Title", JOptionPane.WARNING_MESSAGE);
b=false;
     return false;

}
public  void clearFeild(JTextComponent jTextComponent) {
        jTextComponent.setBackground(Color.WHITE);
    }
public boolean checkFileName(JTextComponent jTextComponent){
        try {


        //    File file=new File
           //Double.parseDouble(jTextComponent.getText());
          // jTextComponent.setBackground(Color.white);
            return true;
        } catch (Exception e) {
        }
        jTextComponent.setBackground(new Style().getTextFieldErrorBlackground());
        JOptionPane.showMessageDialog (null, "please enter the price.", "Title", JOptionPane.WARNING_MESSAGE);
b=false;
    return false;
    }
public boolean checkPasswordLength(JTextComponent jTextComponent){
        jTextComponent.setBackground(Color.white);
        if (jTextComponent.getText().length()==0) {

        jTextComponent.setBackground(new Style().getTextFieldErrorBlackground());
        JOptionPane.showMessageDialog (null, "please enter the Password", "Title", JOptionPane.WARNING_MESSAGE);
        b=false;
    }

    return false;
    }

    public static  boolean textFeildFree(JTextComponent ...component){

        for (JTextComponent jTextComponent : component) {
            jTextComponent.setText("");
        }
    return true;
    }
    
        public   boolean checkEmail(JTextComponent component){
          component.setBackground(Color.white);
         String email = component.getText();
      //Set the email pattern string
      Pattern p = Pattern.compile(".+@.+\\.[a-z]+");

      //Match the given string with the pattern
      Matcher m = p.matcher(email);

      //check whether match is found 
      boolean matchFound = m.matches();

      if (matchFound){

        // JOptionPane.showMessageDialog (null, "please enter the Password", "Title", JOptionPane.WARNING_MESSAGE);
               return true;
      
      }
      else{
           JOptionPane.showMessageDialog (null, "please enter the email Address", "Title", JOptionPane.WARNING_MESSAGE);
      b=false;
      component.setBackground(new Style().getTextFieldErrorBlackground());
      return false;
      
      
      
      }
    }

}
